<template>
	<view class="base-page">
		<view class="yangsf-padding-20 yangsf-flex-col-center">
			<view class="yangsf-radius-20 yangsf-ratio-w-100 logo">
				<image src="/static/img/sfz.jpg" mode="widthFix"></image>
			</view>

			<view class="yangsf-m-t-100 yangsf-ratio-w-100">
				<u--form labelPosition="left" :model="userMsg" :rules="rules" labelWidth="80" ref="uForm">
					<u-form-item label="真实姓名" prop="realname" borderBottom ref="item1">
						<u--input v-model="userMsg.realname" placeholder="填写真实姓名" border="none"></u--input>
					</u-form-item>
					<u-form-item label="身份证号" prop="idcard" borderBottom ref="item1">
						<u--input v-model="userMsg.idcard" placeholder="填写身份证号码" border="none"></u--input>
					</u-form-item>

					<view class="yangsf-m-t-100">
						<u-button type="primary" @click="submit">提交</u-button>
					</view>
				</u--form>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		baseUrl,
		domainNameUrl
	} from '@/config/config.js'
	import {
		submitAuth
	} from '@/config/api.js'
	export default {
		data() {
			return {
				imgUrl: '',

				userMsg: {
					realname: '',
					sex: '',
					idcard: '',

					address: ''
				},
				rules: {
					'realname': [{
						type: 'string',
						required: true,
						message: '真实姓名不能为空',
						trigger: ['blur', 'change']
					}, {
						min: 2,
						message: '姓名长度需要大于2个字符',
						trigger: ['blur', 'change']
					}],
					'idcard': [{
						required: true,
						message: '身份证号不能为空',
						trigger: ['blur', 'change']
					}, {
						validator: (rule, value, callback) => {
							return uni.$u.test.idCard(value);
						},
						message: '身份证号不正确',
						trigger: ['change', 'blur'],
					}],
				}
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {

			submit() {
				this.$refs.uForm.validate().then(res => {
					uni.$u.toast('校验通过')
					let data = {
						realName: this.userMsg.realname,
						idCard: this.userMsg.idcard
					}
					submitAuth(data).then(res => {
						console.log("获取人脸识别地址 ==> {}", res);
						if (res.code == 200) {
							console.log("获取人脸识别地址 ==> {}", res.data);
							uni.$u.route({
								type: 'reLaunch',
								url: '/pages/auth/face',
								params: {
									pageUrl: res.data + ''
								}
							});
						} else {
							uni.$u.toast(res.msg)
						}
					})
				}).catch(errors => {
					uni.$u.toast('校验失败')
				})
			},
		}
	}
</script>

<style scoped>
	.logo>image {
		width: 100%;
		height: 100%;
	}
</style>